
<table width="100%" border="0" align="center">
  <tr>
    <td colspan="4">&nbsp; DAFTAR PRODUK</td>
  </tr>
  <?php
include_once "koneksi/koneksi.php";    //koneksi ke database


// jumlah data yang akan ditampilkan per halaman


$dataPerPage = 6;


// apabila $_GET['page'] sudah didefinisikan, gunakan nomor halaman tersebut,
// sedangkan apabila belum, nomor halamannya 1.


if(isset($_GET['paging'])){
  $noPage = $_GET['paging'];
  $showPage = $noPage;
}
else{ 
  $noPage = 1;
  $showPage = $noPage;
}


// perhitungan offset


$offset = ($noPage - 1) * $dataPerPage;



$sqlstr = "SELECT * FROM _product
LIMIT $offset, $dataPerPage";
$query = mysql_query($sqlstr) or die ("Ada kesalahan ".mysql_error());

while($row=mysql_fetch_array($query))
{
 ?>


 <tr>
  <td><php echo $row[0]; ?></td>
  <!--td><php echo $row[1]; ?></td>
  <td><php echo $row[2]; ?></td>
  <td><php echo $row[3]; ?></td-->
  </tr>
  <?php
}
?>
<tr>
 <td colspan="4" align="center">
   <?php


   $query   = "SELECT COUNT(*) AS jumData FROM _product ";
   $hasil  = mysql_query($query);
   $data     = mysql_fetch_array($hasil);


   $jumData = $data['jumData'];


// menentukan jumlah halaman yang muncul berdasarkan jumlah semua data


   $jumPage = ceil($jumData/$dataPerPage);


// menampilkan link previous


   if ($noPage > 1) echo  "<a  href='".$_SERVER['PHP_SELF']."?paging=".($noPage-1)."'>&lt;&lt; Prev</a>";


// memunculkan nomor halaman dan linknya


   for($page = 1; $page <= $jumPage; $page++)
   {
     if ((($page >= $noPage - 3) && ($page <= $noPage + 3)) || ($page == 1) || ($page == $jumPage))
     {
      if (($showPage == 1) && ($page != 2))  echo "...";
      if (($showPage != ($jumPage - 1)) && ($page == $jumPage))  echo "...";
      if ($page == $noPage) echo " <b>".$page."</b> ";
      else echo " <a href='".$_SERVER['PHP_SELF']."?paging=".$page."'>".$page."</a> ";
      $showPage = $page;
    }
  }


// menampilkan link next


  if ($noPage < $jumPage) echo "<a href='".$_SERVER['PHP_SELF']."?paging=".($noPage+1)."'>Next &gt;&gt;</a>";


  ?> 
</td>
</tr> 
</table>